/**
 * 
 */
package com.jiyinit.web.core.common.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/** 
 * 
 * 
 * 
 * 修改记录
 * -----------------------------------------------
 * 修改日期			修改人			修改内容
 * 
 * @author 作者wuyuefeng: 
 * @version 创建时间：2017年4月25日 下午4:36:37 
 * 类说明 
 */
/**
 * @author yuefengwu
 *
 */
public class DateUtil {
	public static Date getFormatDate(String dateTime){ 
		 Date dateTrans = new Date();
        try {  
        	DateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
            dateTrans = format.parse(dateTime);  
        } catch (ParseException e) {  
            e.printStackTrace();  
        }  
        return dateTrans;
	}
	
	public static String getFormatDateToString(Date dateTime,String formats){ 
		 String dateTrans = null;
		 if(dateTime==null){
			 dateTime = new Date();
		 }
		 DateFormat format = new SimpleDateFormat(formats);  
		 dateTrans = format.format(dateTime);  
		 return dateTrans;
	}
	
	 public int daysBetween(Date smdate,Date bdate) throws ParseException
	    {    
	        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
	        smdate=sdf.parse(sdf.format(smdate));  
	        bdate=sdf.parse(sdf.format(bdate));  
	        Calendar cal = Calendar.getInstance();    
	        cal.setTime(smdate);    
	        long time1 = cal.getTimeInMillis();                 
	        cal.setTime(bdate);    
	        long time2 = cal.getTimeInMillis();         
	        long between_days=(time2-time1)/(1000*3600*24);  
	            
	       return Integer.parseInt(String.valueOf(between_days));           
	    }    
}
